﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


namespace ServeNHL.Models
{
    [MetadataType(typeof(VCLMetadata))]
    public partial class VOLUNTEER_CONTROL_LIST
    {

        public int saveVCL(VOLUNTEER_CONTROL_LIST vcl)
        {
            int vclid = 0;
            if (vcl.VCL_ID != 0)
            {
                updateVCL(vcl);
            }
            else
            {
                insertVCL(vcl);
            }

            vclid = vcl.VCL_ID;

            return vclid;
        }// end of public int saveVCL(VCLViewModel vcl)

        public int insertVCL(VOLUNTEER_CONTROL_LIST vcl)
        {
            int vclid = 0;
            using(var dbconn = new fclick_dbEntities())
            {
               var tempVCL = new VOLUNTEER_CONTROL_LIST {
                   ORG_ID = vcl.ORG_ID,
                   LIST_DESC = vcl.LIST_DESC,
                   STATUS=vcl.STATUS,
                   CREATED_DATE = Helpers.createDate.getCreateDate(),
                   LAST_MOD_DATE = Helpers.createDate.getCreateDate()

               };

                dbconn.VOLUNTEER_CONTROL_LIST.Add(tempVCL);
                dbconn.SaveChanges();


                vclid = tempVCL.VCL_ID;
            }//end of using(var dbconn = new fclick_dbEntities())
            return vclid;


        }//end of public int insertVCL(VOLUNTEER_CONTROL_LIST vcl)


        public int updateVCL(VOLUNTEER_CONTROL_LIST vcl)
        {
            int vclid = 0;

            using (var dbconn = new fclick_dbEntities())
            {
                var tempVCL = new VOLUNTEER_CONTROL_LIST();

                if (vcl.ORG_ID > 0 || !String.IsNullOrEmpty(vcl.ORG_ID.ToString()) )
                { 
                tempVCL.ORG_ID = vcl.ORG_ID;
                }

                if (!String.IsNullOrEmpty(vcl.LIST_DESC))
                {
                    tempVCL.LIST_DESC = vcl.LIST_DESC;
                }

                if (!String.IsNullOrEmpty(vcl.STATUS))
                {
                    tempVCL.STATUS = vcl.STATUS;
                }
                dbconn.VOLUNTEER_CONTROL_LIST.Add(tempVCL);
                dbconn.SaveChanges();


                vclid = tempVCL.VCL_ID;
            }// end of using (var dbconn = new fclick_dbEntities())
            return vclid;

        }//end of public int updateVCL(VOLUNTEER_CONTROL_LIST vcl)

    }//end of partial class vcl
}